//
//  ViewController.swift
//  swift警示框
//
//  Created by cvicseks-mac1 on 16/3/9.
//  Copyright © 2016年 cvicseks-mac1. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var btnClickMe: UIButton = UIButton(frame:CGRect(x: 0, y: 0, width: 200, height: 40))
    var btnAlertC : UIButton = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
    // frame与bounds的区别，frame是相对于父控件的位置bound是相对于自己原点的位置

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        btnClickMe.setTitle("showAlert", forState: UIControlState.Normal)
        btnClickMe.backgroundColor = UIColor.greenColor()
        btnClickMe.center = CGPointMake(160, 100)
        btnClickMe.addTarget(self, action: "showAlert", forControlEvents: UIControlEvents.TouchDragInside)
        view.addSubview(btnClickMe)
        
        btnAlertC.setTitle("showAlertController", forState: .Normal)
        btnAlertC.backgroundColor = UIColor.redColor()
        btnAlertC.center = CGPointMake(160, 200)
        btnAlertC.addTarget(self, action: "showAlertController", forControlEvents: .TouchUpInside)
        view.addSubview(btnAlertC)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func showAlert(){
        let msgTitle = "Welcome to Beijing"
        let message = "dou ni wan"
        let alert: UIAlertView = UIAlertView(title: msgTitle, message: message, delegate: self, cancelButtonTitle: "NO")
        alert.show()
    }
    func showAlertController(){
        let msgTitle = "Welcome to Beijing"
        let message = "dou ni wan"
        let btnNo = "No"
        let btnYes = "Yes"
        
        let alertController: UIAlertController = UIAlertController(title: msgTitle, message: message, preferredStyle: UIAlertControllerStyle.Alert)
        let actionLeft = UIAlertAction(title: btnNo, style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
            NSLog("no")
        }
        let actionRight = UIAlertAction(title: btnYes, style: .Default) { (UIAlertAction) -> Void in
            NSLog("yes")
        }
        alertController.addAction(actionLeft)
        alertController.addAction(actionRight)
        presentViewController(alertController, animated: true, completion: nil)
    }

}

